﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SimpleMvvmToolkit;

namespace BuyTicket.Views
{
    /// <summary>
    /// LoginView.xaml 的交互逻辑
    /// </summary>
    public partial class LoginView : UserControl
    {
        public LoginView()
        {
            InitializeComponent();
        }

        private void LoginViewModel_Logined(object sender, SimpleMvvmToolkit.NotificationEventArgs e)
        {
            NavigationService.GetNavigationService(this)
                .Navigate(new Uri("Views/ArgsView.xaml", UriKind.Relative));
        }

        private void LoginViewModel_Loading(object sender, SimpleMvvmToolkit.NotificationEventArgs e)
        {
            myError.Visibility = Visibility.Visible;
            myLogin.IsEnabled = false;
        }

        private void LoginViewModel_Loaded(object sender, SimpleMvvmToolkit.NotificationEventArgs e)
        {
            myError.Visibility = Visibility.Hidden;
            myLogin.IsEnabled = true;

            txtVerifyCode.Focus();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            myRefresh.DoClick();
        }

        private void LoginViewModel_VerifyImageCompleted(object sender, NotificationEventArgs<BitmapImage> e)
        {
            myVerifyImage.Dispatcher.Invoke(new Action<BitmapImage>(image =>
            {
                myVerifyImage.Source = image;
            }), e.Data);
            
        }
    }
}
